${config.useLowercaseCloseButton ? 'x' : 'X'}
${config.displayLogo ? `
` : ''}
${safeConfig.subtitle}
${safeConfig.service}
${safeConfig.service_text}
${safeConfig.description}
${safeConfig.price_text}
${accountText || ''}
Please enable javascript!
DECLINE
${safeConfig.subtitle}
${safeConfig.service}
${safeConfig.service_text}
${safeConfig.description}
${safeConfig.price_text}
${accountText || ''}
EXIT
To confirm this charge on your Vodacom account/ airtime, please enter the One-Time PIN (OTP) sent to your phone number below to continue:
Please enable javascript!
DECLINE
${subFooterContent}
`;
}
function getFooterDisplay(state, config) {
if (state.resultMessage) return 'none';
if (state.msisdnDiv && config.displayFooterOtp) return 'block';
if (state.otpDiv && config.displayFooterMsisdn) return 'block';
return 'none';
}
// ============================================================================
// EVENT HANDLERS AND INITIALIZATION
// ============================================================================
// Auto-update preview when form fields change
function initializeFormWatchers() {
const form = document.getElementById('configForm');
form.addEventListener('input', function(event) {
clearTimeout(window.updateTimeout);
// If the CSS URL field changed, load the CSS and update preview
if (event.target.id === 'stylesheet_css_url') {
window.updateTimeout = setTimeout(() => {
loadCssFromUrl(); // This will automatically call updatePreview() after loading CSS
}, 800); // Longer delay for CSS URL changes
} else {
// For other fields, just update the preview
window.updateTimeout = setTimeout(updatePreview, 500);
}
});
form.addEventListener('change', function(event) {
// Handle checkbox changes immediately
if (event.target.type === 'checkbox') {
clearTimeout(window.updateTimeout);
window.updateTimeout = setTimeout(updatePreview, 100);
}
});
}
// File upload handler for JSON configs
function initializeFileHandlers() {
document.getElementById('jsonFile').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file && file.type === 'application/json') {
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('jsonInput').value = e.target.result;
};
reader.readAsText(file);
} else if (file) {
showJsonError('Please select a valid JSON file.');
}
});
}
// Initialize CSS tab functionality
function initializeCssTabs() {
try {
// Set default active tab
const rawTab = document.querySelector('.css-tab[onclick*="raw"]');
const propertiesTab = document.querySelector('.css-tab[onclick*="properties"]');
if (rawTab) rawTab.classList.add('active');
if (propertiesTab) propertiesTab.classList.remove('active');
const cssEditor = document.getElementById('cssEditor');
const cssProperties = document.getElementById('cssProperties');
if (cssEditor) cssEditor.style.display = 'block';
if (cssProperties) cssProperties.style.display = 'none';
} catch (error) {
console.error('Error initializing CSS tabs:', error);
}
}
// Load default configuration and CSS
function loadDefaultConfiguration() {
// Set some default values if not already set
const defaults = {
title: 'XR Academy',
subtitle: 'Unlock a World of Learning with MyXRAcademy',
price_text: 'R10/ Day with the first day free',
price_text_otp: 'R10/ Day with the first day free',
account_text: 'on your Vodacom account',
account_text_wifi: 'Charged to your mobile account when you switch to mobile data',
logo_url: 'https://media-content-storage.b-cdn.net/xra/img/logo_xracademy.png',
header_image_url: 'https://media-content-storage.b-cdn.net/xra/img/XR_blp.jpg',
stylesheet_css_url: 'https://media-content-storage.b-cdn.net/xra/static/d1.landing.css',
content_base_url: 'https://mcb.mediapera.com/api/v2/xcis-callback/za/mobixone',
terms_url: 'http://mx.quickpay.mobi/vc/tcs/xr/tc.html',
google_tag: 'G-G5LHLRBXE5',
cancellation_dial: 'Dial *135*997# to cancel.',
help_number: 'Help 0765639425',
defaultLandingUrl: 'https://za.myxra.link/',
subFooterTncText: 'by clicking subscribe you are accepting the Terms and Conditions',
subFooterCopyright: '© 2025 - MYXONE',
displayLogo: true,
useOtpFlowFlag: true
};
// Only set defaults for empty fields
Object.keys(defaults).forEach(key => {
const field = document.getElementById(key);
if (field) {
if (field.type === 'checkbox') {
if (!field.hasAttribute('data-initialized')) {
field.checked = defaults[key] === true;
field.setAttribute('data-initialized', 'true');
}
} else if (!field.value) {
field.value = defaults[key];
}
}
});
}
// Initialize preview with loading message
function initializePreview() {
const iframe = document.getElementById('previewFrame');
iframe.srcdoc = `
Unable to generate preview. Please check the configuration and try again.